//
//  ZTCarTableViewCell.m
//  CarTown
//
//  Created by xionghao on 15/8/26.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "ZTCarTableViewCell.h"
#import "ZCModel.h"
#import <UIImageView+WebCache.h>
@interface ZTCarTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *photo;
@property (weak, nonatomic) IBOutlet UILabel *carname;
@property (weak, nonatomic) IBOutlet UILabel *subtitle;
@property (weak, nonatomic) IBOutlet UILabel *price;
@property (weak, nonatomic) IBOutlet UILabel *time;
@property (weak, nonatomic) IBOutlet UILabel *saveprice;
@property (weak, nonatomic) IBOutlet UILabel *typelable;



@end

@implementation ZTCarTableViewCell
-(void)setIsShowEidt:(BOOL)isShowEidt{
    _isShowEidt=isShowEidt;
    self.editbutton.hidden=!_isShowEidt;
}
+(instancetype)cellWithTableView:(UITableView *)tableView{
    ZTCarTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"ztcar"];
    if (cell==nil) {
        [tableView registerNib:[UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil] forCellReuseIdentifier:@"ztcar"];
        cell=[tableView dequeueReusableCellWithIdentifier:@"ztcar"];
    }
    return cell;
}
-(void)setMode:(ZCModel *)mode{
    _mode=mode;
    self.editbutton.selected=_mode.ischecked;
    self.carname.text=_mode.cat_name;
    self.subtitle.text=[NSString stringWithFormat:@"%@|%@/%@",_mode.name,_mode.car_outside_color,_mode.car_inside_color];
    float pricenumber=[_mode.allprice floatValue]/10000;
    
    self.price.text=[NSString stringWithFormat:@"%.2f万",pricenumber];
    self.saveprice.text=[NSString stringWithFormat:@"省:%@元",_mode.yhprice];
    if ([_mode.price_gzs integerValue]!=0) {
        self.typelable.text=@"全包价";
        self.typelable.backgroundColor=[UIColor redColor];
        self.price.textColor=[UIColor redColor];
    }else{
        self.typelable.text=@"车身价";
        self.typelable.backgroundColor=tintblue;
        self.price.textColor=tintblue;
    }
    self.time.text=[NSDate dateStrFromTimeStr:_mode.updatetime];
    NSString *url;
    if (_mode.pic&&![_mode.pic isEqualToString:@""]) {
        url=_mode.pic;
    }else{
        url=_mode.brand_logo;
    }
    [self.photo sd_setImageWithURL:[NSURL URLWithString:[NSString getImageURLstr:url]] placeholderImage:[UIImage imageNamed:@"暂无照片"]];
}
- (void)awakeFromNib {
    // Initialization code
    self.typelable.layer.cornerRadius=5;
    self.typelable.backgroundColor=tintblue;
    self.typelable.clipsToBounds=YES;
    self.typelable.textColor=[UIColor whiteColor];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
